package net.oschina.app.fragment.center_message;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.chanven.lib.cptr.recyclerview.RecyclerAdapterWithHF;

import net.oschina.app.adapter.center_message.GoodsAdapter;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.base.BaseFragment;
import net.oschina.app.bean.PraiseBean;
import net.oschina.app.interf.FragmentType;
import net.oschina.app.protocol.me_messager.GoodsProtocol;
import net.oschina.app.ui.DetailFragmentActivity;
import net.oschina.app.util.CommonUtils;

import java.util.List;

/**
 * Created by wei03 on 2017/1/14.
 */
public class GoodsFragment extends BaseFragment {
    private GoodsAdapter mGoodsAdapter;
    private List<PraiseBean.MytweetBean> likeList;
    @Override
    protected BaseAdapter getRvAdapter() {
        mGoodsAdapter = new GoodsAdapter();
        return mGoodsAdapter;
    }

    @Override
    protected void OnSubItemClick(RecyclerAdapterWithHF adapter, RecyclerView.ViewHolder vh, int position) {
        Intent intent = new Intent(CommonUtils.getContext(), DetailFragmentActivity.class);
        intent.putExtra(FragmentType.FRAGMENT_TYPE, FragmentType.TYPE_ME_GOODS_DETAIL);
        PraiseBean.MytweetBean mytweetBean = likeList.get(position);
        Bundle bundle = new Bundle();
        bundle.putSerializable("bean", mytweetBean);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    @Override
    protected int onLoadSubData() {
        GoodsProtocol goodsProtocol = new GoodsProtocol();
        final PraiseBean praiseBean = goodsProtocol.getData(mList.size() / 2);

            CommonUtils.runOnMainThread(new Runnable() {
                @Override
                public void run() {
                    likeList = praiseBean.getLikeList();
                    mGoodsAdapter.setDatas(likeList);
                }
            });
            return STATE_SUCCESS;

    }
}
